package com.pphh.demo.amqp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.stereotype.Service;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 2019/3/27
 */
@Service
public class MqListener implements MessageListener {

    private final static Logger log = LoggerFactory.getLogger(MqListener.class);

    @Override
    public void onMessage(Message message) {
        String msg = null;
        try {
            msg = new String(message.getBody());
            log.info("received a message from mq, msg = {}", msg);
            MessageProperties properties = message.getMessageProperties();
            Helper.logMessageProperties(properties);
        } catch (Exception e) {
            log.error("异常消息，exception = {}", e.getMessage());
        }
    }

}
